package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Result;
import cn.wolfcode.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/upload")
public class UpLoadController {
    //    @Value("file.upload")
//    private String path;

    @Autowired
    private EmpService empService;

    @PostMapping
    public Result upload(@RequestParam("image") MultipartFile file) throws IOException {
        log.info("文件上传,{}", file);
        return  empService.empUpLoad(file);
    }

//        log.info("文件上传,{}", file);
//        // 选择存储地址  磁盘路径 + 文件名.后缀
//        //获取上传文件的原始名字
//        String originalFilename = file.getOriginalFilename();
//        //
////        String path = "C:\\Users\\123\\Desktop\\ideajava\\demo2\\Java61_SpringBoot_Boss\\src\\main\\resources\\static";
////        xxx.文件格式
//        String newFileName = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
//        String newName = path + "\\" + newFileName;
//        try {
//            file.transferTo(new File(newName));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        return Result.success("http://localhost:8080/" + newFileName);

}
